namespace SmartSoft.SystemForms
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormPriceCalculate : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private IContainer components;
        private GBoxControl gBoxControl1;
        private LabelControl lblMa_Kho;
        private LabelControl lblMa_Vt;
        private LabelControl lblNgay_Ct1;
        private LabelControl lblNgay_Ct2;
        private TextSearch txtMa_Kho;
        private TextSearch txtMa_Vt;
        private TextDate txtNgay_Ct1;
        private TextDate txtNgay_Ct2;
        private TextControl txtTen_Kho;
        private TextControl txtTen_Vt;

        public FormPriceCalculate()
        {
            this.InitializeComponent();
            this.txtNgay_Ct1.Value = AppInstance.StartWorkingDate;
            this.txtNgay_Ct2.Value = AppInstance.EndWorkingDate;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if ((this.txtNgay_Ct1.Value == SDBNull.Value) || (this.txtNgay_Ct2.Value == SDBNull.Value))
            {
                MessageBox.Show("Chưa nhập ngày tính giá!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if ((((DateTime) this.txtNgay_Ct2.Value) < AppInstance.OpeningDateOfSubEnterprice) || (((DateTime) this.txtNgay_Ct2.Value) <= AppInstance.EndingDateOfSubEnterprice))
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                this.Calculate();
            }
        }

        private void Calculate()
        {
            if ((this.txtNgay_Ct1.Value == SDBNull.Value) || (this.txtNgay_Ct2.Value == SDBNull.Value))
            {
                MessageBox.Show("Chưa nhập ngày để tính giá xuất kho!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (((DateTime) this.txtNgay_Ct1.Value) > ((DateTime) this.txtNgay_Ct2.Value))
            {
                MessageBox.Show("Ngày bắt đầu không được lớn hơn ngày kết th\x00fac!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (((DateTime) this.txtNgay_Ct1.Value) < AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Ngày phải bắt đầu từ " + AppInstance.OpeningDateOfSubEnterprice.ToShortDateString() + "!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                AppInstance.StartWorkingDate = (DateTime) this.txtNgay_Ct1.Value;
                AppInstance.EndWorkingDate = (DateTime) this.txtNgay_Ct2.Value;
                PriceCalculateDataAccess access = new PriceCalculateDataAccess();
                if (AppInstance.CostingMethod == 0)
                {
                    access.Calculate0(AppInstance.Subsidiary, this.txtNgay_Ct1.Value, this.txtNgay_Ct2.Value, this.txtMa_Kho.Value, this.txtMa_Vt.Value);
                }
                else if (AppInstance.CostingMethod == 1)
                {
                    access.Calculate1(AppInstance.Subsidiary, this.txtNgay_Ct1.Value, this.txtNgay_Ct2.Value, this.txtMa_Kho.Value, this.txtMa_Vt.Value);
                }
                else if (AppInstance.CostingMethod == 2)
                {
                    access.Calculate2(AppInstance.Subsidiary, this.txtNgay_Ct1.Value, this.txtNgay_Ct2.Value, this.txtMa_Kho.Value, this.txtMa_Vt.Value);
                }

                MessageBox.Show(AppInstance.EndMessage, AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                base.Close();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormPriceCalculate));
            this.txtNgay_Ct2 = new TextDate();
            this.lblNgay_Ct2 = new LabelControl();
            this.txtNgay_Ct1 = new TextDate();
            this.lblNgay_Ct1 = new LabelControl();
            this.btnCancel = new BtnControl();
            this.btnOk = new BtnControl();
            this.gBoxControl1 = new GBoxControl();
            this.txtTen_Kho = new TextControl();
            this.txtMa_Kho = new TextSearch();
            this.lblMa_Kho = new LabelControl();
            this.txtTen_Vt = new TextControl();
            this.txtMa_Vt = new TextSearch();
            this.lblMa_Vt = new LabelControl();
            this.gBoxControl1.SuspendLayout();
            base.SuspendLayout();
            this.txtNgay_Ct2.DateTimeFormat = TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct2.Font = new Font("Arial", 8.25f);
            this.txtNgay_Ct2.InsertKeyMode = InsertKeyMode.Overwrite;
            this.txtNgay_Ct2.Location = new Point(0x11a, 0x24);
            this.txtNgay_Ct2.Mask = "00/00/0000";
            this.txtNgay_Ct2.Name = "txtNgay_Ct2";
            this.txtNgay_Ct2.OldValue = null;
            this.txtNgay_Ct2.Size = new Size(100, 20);
            this.txtNgay_Ct2.TabIndex = 1;
//            this.txtNgay_Ct2.Value = null;//manager.GetObject("txtNgay_Ct2.Value");
            this.lblNgay_Ct2.AutoSize = true;
            this.lblNgay_Ct2.Font = new Font("Arial", 8.25f);
            this.lblNgay_Ct2.Location = new Point(0xde, 0x27);
            this.lblNgay_Ct2.Name = "lblNgay_Ct2";
            this.lblNgay_Ct2.Size = new Size(0x36, 14);
            this.lblNgay_Ct2.TabIndex = 4;
            this.lblNgay_Ct2.Text = "Đến ngày";
            this.txtNgay_Ct1.DateTimeFormat = TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct1.Font = new Font("Arial", 8.25f);
            this.txtNgay_Ct1.InsertKeyMode = InsertKeyMode.Overwrite;
            this.txtNgay_Ct1.Location = new Point(90, 0x24);
            this.txtNgay_Ct1.Mask = "00/00/0000";
            this.txtNgay_Ct1.Name = "txtNgay_Ct1";
            this.txtNgay_Ct1.OldValue = null;
            this.txtNgay_Ct1.Size = new Size(100, 20);
            this.txtNgay_Ct1.TabIndex = 0;
//            this.txtNgay_Ct1.Value = null;//manager.GetObject("txtNgay_Ct1.Value");
            this.lblNgay_Ct1.AutoSize = true;
            this.lblNgay_Ct1.Font = new Font("Arial", 8.25f);
            this.lblNgay_Ct1.Location = new Point(13, 0x27);
            this.lblNgay_Ct1.Name = "lblNgay_Ct1";
            this.lblNgay_Ct1.Size = new Size(0x2f, 14);
            this.lblNgay_Ct1.TabIndex = 3;
            this.lblNgay_Ct1.Text = "Từ ngày";
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            //this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Font = new Font("Arial", 8.25f);
            this.btnCancel.Location = new Point(0x13b, 0x9e);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x5e, 0x17);
            this.btnCancel.TabIndex = 2;
            this.btnCancel.Text = "&Huỷ bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnOk.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnOk.Font = new Font("Arial", 8.25f);
            this.btnOk.Location = new Point(0xd7, 0x9e);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new Size(0x5e, 0x17);
            this.btnOk.TabIndex = 1;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new EventHandler(this.btnOk_Click);
            this.gBoxControl1.Controls.Add(this.txtTen_Kho);
            this.gBoxControl1.Controls.Add(this.txtMa_Kho);
            this.gBoxControl1.Controls.Add(this.txtNgay_Ct2);
            this.gBoxControl1.Controls.Add(this.lblNgay_Ct2);
            this.gBoxControl1.Controls.Add(this.lblMa_Kho);
            this.gBoxControl1.Controls.Add(this.txtTen_Vt);
            this.gBoxControl1.Controls.Add(this.txtNgay_Ct1);
            this.gBoxControl1.Controls.Add(this.lblNgay_Ct1);
            this.gBoxControl1.Controls.Add(this.txtMa_Vt);
            this.gBoxControl1.Controls.Add(this.lblMa_Vt);
            this.gBoxControl1.Font = new Font("Arial", 8.25f);
            this.gBoxControl1.Location = new Point(12, 12);
            this.gBoxControl1.Name = "gBoxControl1";
            this.gBoxControl1.Size = new Size(0x18d, 0x83);
            this.gBoxControl1.TabIndex = 0;
            this.gBoxControl1.TabStop = false;
            this.txtTen_Kho.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Kho.BackColor = SystemColors.Control;
            this.txtTen_Kho.BorderStyle = BorderStyle.None;
            this.txtTen_Kho.CheckTextSearched = false;
            this.txtTen_Kho.DisabledForeColor = Color.Blue;
            this.txtTen_Kho.Enabled = false;
            this.txtTen_Kho.Font = new Font("Arial", 8.25f);
            this.txtTen_Kho.ForeColor = Color.Blue;
            this.txtTen_Kho.Location = new Point(0xc4, 0x3d);
            this.txtTen_Kho.Name = "txtTen_Kho";
            this.txtTen_Kho.OldValue = null;
            this.txtTen_Kho.Size = new Size(0xba, 13);
            this.txtTen_Kho.TabIndex = 110;
//            this.txtTen_Kho.Value = null;//manager.GetObject("txtTen_Kho.Value");
            this.txtMa_Kho.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Kho.CheckTextSearched = false;
            this.txtMa_Kho.DisabledForeColor = Color.Empty;
            this.txtMa_Kho.EmptyIsValid = true;
            this.txtMa_Kho.FieldDisplay = "Ten_Kho";
            this.txtMa_Kho.Font = new Font("Arial", 8.25f);
            this.txtMa_Kho.FoundIsValid = true;
            this.txtMa_Kho.Location = new Point(90, 0x3a);
            this.txtMa_Kho.MaxLength = 0x20;
            this.txtMa_Kho.Name = "txtMa_Kho";
            this.txtMa_Kho.OldValue = null;
            this.txtMa_Kho.Size = new Size(100, 20);
            this.txtMa_Kho.TabIndex = 2;
            this.txtMa_Kho.TableName = "DMKHO";
            this.txtMa_Kho.TextDisplay = this.txtTen_Kho;
            this.txtMa_Kho.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Kho.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Kho.Value = null;//manager.GetObject("txtMa_Kho.Value");
            this.lblMa_Kho.AutoSize = true;
            this.lblMa_Kho.Font = new Font("Arial", 8.25f);
            this.lblMa_Kho.Location = new Point(13, 0x3d);
            this.lblMa_Kho.Name = "lblMa_Kho";
            this.lblMa_Kho.Size = new Size(0x29, 14);
            this.lblMa_Kho.TabIndex = 0x72;
            this.lblMa_Kho.Text = "Mã kho";
            this.txtTen_Vt.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Vt.BackColor = SystemColors.Control;
            this.txtTen_Vt.BorderStyle = BorderStyle.None;
            this.txtTen_Vt.CheckTextSearched = false;
            this.txtTen_Vt.DisabledForeColor = Color.Blue;
            this.txtTen_Vt.Enabled = false;
            this.txtTen_Vt.Font = new Font("Arial", 8.25f);
            this.txtTen_Vt.ForeColor = Color.Blue;
            this.txtTen_Vt.Location = new Point(0xc4, 0x53);
            this.txtTen_Vt.Name = "txtTen_Vt";
            this.txtTen_Vt.OldValue = null;
            this.txtTen_Vt.Size = new Size(0xba, 13);
            this.txtTen_Vt.TabIndex = 0x70;
//            this.txtTen_Vt.Value = null;//manager.GetObject("txtTen_Vt.Value");
            this.txtMa_Vt.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Vt.CheckTextSearched = false;
            this.txtMa_Vt.DisabledForeColor = Color.Empty;
            this.txtMa_Vt.EmptyIsValid = true;
            this.txtMa_Vt.FieldDisplay = "Ten_Vt";
            this.txtMa_Vt.Font = new Font("Arial", 8.25f);
            this.txtMa_Vt.FoundIsValid = true;
            this.txtMa_Vt.Location = new Point(90, 80);
            this.txtMa_Vt.MaxLength = 0x20;
            this.txtMa_Vt.Name = "txtMa_Vt";
            this.txtMa_Vt.OldValue = null;
            this.txtMa_Vt.Size = new Size(100, 20);
            this.txtMa_Vt.TabIndex = 3;
            this.txtMa_Vt.TableName = "DMVT";
            this.txtMa_Vt.TextDisplay = this.txtTen_Vt;
            this.txtMa_Vt.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Vt.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Vt.Value = null;//manager.GetObject("txtMa_Vt.Value");
            this.lblMa_Vt.AutoSize = true;
            this.lblMa_Vt.Font = new Font("Arial", 8.25f);
            this.lblMa_Vt.Location = new Point(13, 0x53);
            this.lblMa_Vt.Name = "lblMa_Vt";
            this.lblMa_Vt.Size = new Size(0x34, 14);
            this.lblMa_Vt.TabIndex = 0x71;
            this.lblMa_Vt.Text = "Mã vật tư";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.CancelButton = this.btnCancel;
            base.ClientSize = new Size(0x1a5, 0xc1);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOk);
            base.Controls.Add(this.gBoxControl1);
            //base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FormPriceCalculate";
            this.Text = "T\x00ednh giá xuất kho";
            this.gBoxControl1.ResumeLayout(false);
            this.gBoxControl1.PerformLayout();
            base.ResumeLayout(false);
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.Calculate();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    }
}

